<%--
  Created by IntelliJ IDEA.
  User: B饭老司机
  Date: 2024/3/23
  Time: 17:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="myUtil.personCheck"%>
<%@ page import="java.sql.*" %>
<%@ page import="myUtil.personCheck" %>
<html>
<head>
    <title>person_save</title>
</head>
<body>
<%
    String worknumber = request.getParameter("worknumber");
    String name = request.getParameter("name");
    String department = request.getParameter("department");
    String worktime = request.getParameter("worktime");
    String degree = request.getParameter("degree");
    String profession = request.getParameter("profession");
    String title = request.getParameter("title");
    String phonenumber = request.getParameter("phonenumber");
    String address = request.getParameter("address");
    String introduction = request.getParameter("introduction");
    if (personCheck.checkNumber(worknumber) && personCheck.checkS(name) && personCheck.checkS(department) &&
            personCheck.checkS(degree) && personCheck.checkS(profession) && personCheck.checkS(title) && personCheck.checkPhonenumber(phonenumber)) {
        Connection conn = (Connection)session.getAttribute("Connection");
        String sql;
        sql = "insert into people(worknumber, name, department, worktime, degree, profession, title, phonenumber, address, introduction) values(?,?,?,?,?,?,?,?,?,?)";

        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setString(1, worknumber);
        preparedStatement.setString(2, name);
        preparedStatement.setString(3, department);
        preparedStatement.setString(4, worktime);
        preparedStatement.setString(5, degree);
        preparedStatement.setString(6, profession);
        preparedStatement.setString(7, title);
        preparedStatement.setString(8, phonenumber);
        preparedStatement.setString(9, address);
        preparedStatement.setString(10, introduction);

        int rowsUpdated = preparedStatement.executeUpdate();
        if (rowsUpdated > 0) {

        } else {

        }

        response.sendRedirect("person_list.jsp");
    } else {
        request.getRequestDispatcher("person_add.jsp").forward(request, response);
    }

%>
</body>
</html>
